define([
    'jquery',
    'underscore',
    'backbone',
    'text!template/backyard/manage/parameter_personnel_item.html',
    'collection/backyard/manage/parameter_personnel_list'
], function($, _, Backbone, ItemTemplate, PersonnelCollection) {

    return Backbone.View.extend({
        el: '[bb-place-personnel]',
        template: _.template(ItemTemplate),

        initialize: function() {
            var _this = this;

            var personnelCollection = new PersonnelCollection();
            personnelCollection.fetch({
                success: function(personnels) {
                    _this.$el.find('tbody').empty();

                    var personnelsData = personnels.toJSON();
                    for (var i=0; i<personnelsData.length; i++) {
                        var _per = personnelsData[i];
                        _this.$el.find('tbody').append(_this.template({
                            workno: _per.workno,
                            name: _per.name,
                            domain: _per.domain,
                            position: _per.position,
                            id: _per.id
                        }));
                    }
                }
            });
        }
    });
});
